<?php
/*
 * Template Name: water use diagram page
 */
global $chart;
?>
 <?php get_header(); ?>

<div id="content">
	<div class="padder">

		<?php do_action( 'bp_before_blog_page' ); ?>

		<div class="page" id="blog-page" role="main">

			<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

				<h2 class="pagetitle"><?php the_title(); ?></h2>

			<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

				<div class="entry">

					<form action="" method="post" id="water_use_options_form">
						<h3>
							<label for="ChartType">Select a chart type</label>
						</h3>
						<p>
							<select name="chartType">
								<option value="Select">Select...</option>
								<option value="Area">Area</option>
								<option value="Bar">Bar</option>
								<option value="Bubble">Bubble</option>
								<option value="Candlestick">Candlestick</option>
								<option value="Column">Column</option>
								<option value="Combo">Combo</option>
								<option value="Histogram">Histogram</option>
								<option value="Line">Line</option>
								<option value="Pie">Pie</option>
								<option value="Scatter">Scatter</option>
								<option value="Stepped">Stepped</option>
							</select>
						</p>
						<p class="submit">
							<input type="submit" name="submit" value="Update" />
						</p>
                     <?php wp_nonce_field('content_update','content_nonce'); ?>
                     </form>
					<?php
					if (is_user_logged_in ()) {
						
						$user_info = wp_get_current_user ();
						global $wpdb;
						$users = $wpdb->get_results ( "SELECT * FROM wp_users where ID=" . $user_info->ID . ";" );
						echo "<table>";
						echo "<tr>";
						echo "<td> Email</td>";
						echo "<td> Name</td>";
						echo "</tr>";
						foreach ( $users as $user ) {
							echo "<tr>";
							echo "<td>" . $user->user_email . "</td>";
							echo "<td>" . $user->user_nicename . "</td>";
							echo "</tr>";
						}
						echo "</table>";
						
						if ((! empty ( $_POST ['chartType'] )) && check_admin_referer ( 'content_update', 'content_nonce' )) {
							$chart = $_POST ['chartType'];
							$uid = $user_info->ID;
							echo "<h4><label>" . $chart . " Chart </label></h4>";
							
							if ($chart == 'Select') {
								//echo do_shortcode ( '[gdoc key="https://docs.google.com/spreadsheets/d/1H1dyKC3czPy_P0Gpqy7AhbW2PPvnBoBeiPvtKgW6xYU/edit" query="select B , C where A=' . $uid . ' "]' );
							} else {
								echo do_shortcode ( '[gdoc key="https://docs.google.com/spreadsheets/d/1H1dyKC3czPy_P0Gpqy7AhbW2PPvnBoBeiPvtKgW6xYU/edit" chart=' . $chart . ' query="select B, C where A=' . $uid . ' "]' );
							}
						}
					} else {
						echo "Sorry, only registered users can view this information";
					}
					
					// - - - snip - - -
					
					// echo 'Username: ' . $user_info->user_login . "\n";
					// echo 'User roles: ' . implode(', ', $user_info->roles) . "\n";
					// echo 'User ID: ' . $user_info->ID . "\n";
					?> 
						<?php wp_link_pages( array( 'before' => '<div class="page-link"><p>' . __( 'Pages: ', 'buddypress' ), 'after' => '</p></div>', 'next_or_number' => 'number' ) ); ?>
						<?php edit_post_link( __( 'Edit this page.', 'buddypress' ), '<p class="edit-link">', '</p>'); ?>

					</div>

			</div>

			<?php comments_template(); ?>

			<?php endwhile; endif; ?>

		</div>
		<!-- .page -->

		<?php do_action( 'bp_after_blog_page' ); ?>

		</div>
	<!-- .padder -->
</div>
<!-- #content -->

<?php get_sidebar(); ?>

<?php get_footer(); ?>
